import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Effects
import "../component" as C

Rectangle {
    id: userPageRoot
    color: "transparent"
    anchors.margins: 20
    radius: 50
    clip: true
    visible: true
    Theme { id: theme }
    FontLoader {
        id: iconFont
        source: "qrc:/assets/fontawesome-free-6.7.2-desktop/otfs/Font Awesome 6 Free-Solid-900.otf"
    }

    property alias userPageTitle: userTitle.text
    // 单选按钮状态
    property bool yesSelected: false
    property bool noSelected: true
    property int selectedRole: 2 // 0=系统管理员, 1=管理员, 2=操作员, 3=查看员

    // 错误提示状态
    property string errorMessage: ""
    property bool showError: false
    property int rowIndex:-1

    function fillData(index, data) {
        rowIndex= index;
        product.valueText = data.product
        batchNo.valueText = data.batch_no
        workshop.valueText = data.work_shop
        beginTime.valueText = data.begin_time
        endTime.valueText = data.end_time

    }
    function clearData(){
        // rowIndex= -1;
        // inputAccount.text = ""
        // inputPassword.text = ""
        // inputName.text = ""
        // yesSelected = true
        // noSelected = !yesSelected
        // selectedRole = 1;
        // userTitle.text="批次结果"
    }

    Rectangle {
        id: batchCard
        anchors.fill: parent
        anchors.margins: 0
        color: "transparent"

        RowLayout {
            id: title
            spacing:500
            width: parent.width
            Layout.alignment: Qt.AlignTop

            Item{
                id: backBtn
                Layout.leftMargin: 30
                Layout.alignment: Qt.AlignTop
                C.ZButtonImage{
                    btnImagePressed: "qrc:/assets/back_pressed.png"
                    btnImage:"qrc:/assets/back.png"
                    onClicked: {
                        console.log("返回")
                        swipeView.currentIndex =0;
                        showError = false;
                    }
                }
            }

            Label {
                id: userTitle
                Layout.alignment: Qt.AlignTop
                text: "                批次结果"
                font.pixelSize: 44
                font.bold: true
                color: "#333"
            }
            RowLayout {
                spacing:12
                width: 300
                Layout.alignment: Qt.AlignTop | Qt.AlignRight
                Item{
                    width:70
                    height:70
                    C.ZButtonImage{
                        btnImage: "qrc:/assets/print@2x.png"
                        btnImagePressed: "qrc:/assets/print.png"
                        onClicked: {
                            console.log("打印")
                        }
                    }
                }
                Item{
                    width:70
                    height:70
                    C.ZButtonImage{
                        btnImage: "qrc:/assets/pos.png"
                        btnImagePressed: "qrc:/assets/pos.png"
                        onClicked: {
                            console.log("打印")
                        }
                    }
                }
                Item{
                    width:70
                    height:70
                    C.ZButtonImage{
                        btnImage: "qrc:/assets/pdf.png"
                        btnImagePressed: "qrc:/assets/pdf.png"
                        onClicked: {
                            console.log("打印")
                        }
                    }
                }
            }
        }

        Flickable {
            id: scrollFlick
            anchors.top: parent.top
            anchors.topMargin: 85
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: parent.bottom

            clip: true
            interactive: true
            boundsBehavior: Flickable.DragOverBounds
            pressDelay: 120

            // 禁用水平拖动
            flickableDirection: Flickable.VerticalFlick

            contentWidth: width
            contentHeight: content.height
            ScrollBar.vertical: ScrollBar {
                policy: ScrollBar.AsNeeded
                visible: scrollFlick.contentHeight > scrollFlick.height && (scrollFlick.moving || scrollFlick.flicking || scrollFlick.dragging)
            }
            Column {
                id: content
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.leftMargin: 30
                anchors.rightMargin: 20
                spacing: 44
                Rectangle{
                    x:0;y:0;
                    width: parent.width
                    height:569
                    topLeftRadius: 8
                    topRightRadius: 8
                    color:"#178FCD"
                    Rectangle{
                        x:50;y:18;width:16;height:31;
                        color:"#FFFFFF"
                    }
                    Label{
                        x:78;y:14;
                        color:"#FFFFFF"
                        text:"搅拌过程参数信息"
                        verticalAlignment: "AlignVCenter"
                        font.pixelSize: 30
                    }

                    Rectangle{
                        y:68;
                        width: parent.width
                        height:501
                        color:"#FFFFFF"
                        Grid {
                            anchors.fill: parent
                            anchors.leftMargin: 51
                            anchors.topMargin: 40
                            columns: 2  // 2列
                            rows: 4     // 3行
                            spacing: 1 // 元素间距
                            C.ZLabelValue{
                                id: name
                                labelText:"用户:";valueText: "1111111";
                                width: (parent.width - parent.spacing) / parent.columns
                                height: (parent.height - (parent.rows-1)*parent.spacing) / parent.rows
                            }
                            C.ZLabelValue{
                                id: realName
                                labelText:"姓名:";valueText: "1111111";
                                width: (parent.width - parent.spacing) / parent.columns
                                height: (parent.height - (parent.rows-1)*parent.spacing) / parent.rows
                            }
                            C.ZLabelValue{
                                id: product
                                labelText:"产品:";valueText: "1111111";
                                width: (parent.width - parent.spacing) / parent.columns
                                height: (parent.height - (parent.rows-1)*parent.spacing) / parent.rows
                            }
                            C.ZLabelValue{
                                id: batchNo
                                labelText:"批号:";valueText: "123123";
                                width: (parent.width - parent.spacing) / parent.columns
                                height: (parent.height - (parent.rows-1)*parent.spacing) / parent.rows
                            }
                            C.ZLabelValue{
                                id: workshop
                                labelText:"车间:";valueText: "车间1";
                                width: (parent.width - parent.spacing) / parent.columns
                                height: (parent.height - (parent.rows-1)*parent.spacing) / parent.rows
                            }
                            C.ZLabelValue{
                                id: beginTime
                                labelText:"开始时间:";valueText: "2023/09/26 09:10";
                                width: (parent.width - parent.spacing) / parent.columns
                                height: (parent.height - (parent.rows-1)*parent.spacing) / parent.rows
                            }
                            C.ZLabelValue{
                                id: endTime
                                labelText:"结束时间:";valueText: "2023/09/26 09:50";
                                width: (parent.width - parent.spacing) / parent.columns
                                height: (parent.height - (parent.rows-1)*parent.spacing) / parent.rows
                            }
                            C.ZLabelValue{
                                id: desc
                                labelText:"备注:";valueText: "1111111";
                                width: (parent.width - parent.spacing) / parent.columns
                                height: (parent.height - (parent.rows-1)*parent.spacing) / parent.rows
                            }
                        }
                    }
                }

                Rectangle{
                    width: parent.width
                    height:444
                    topLeftRadius: 8
                    topRightRadius: 8
                    color:"#178FCD"
                    Rectangle{
                        x:50;y:18;width:16;height:31;
                        color:"#FFFFFF"
                    }
                    Label{
                        x:78;y:14;
                        color:"#FFFFFF"
                        text:"搅拌过程数据曲线"
                        verticalAlignment: "AlignVCenter"
                        font.pixelSize: 30
                    }
                    Rectangle{
                        y:68;
                        width: parent.width
                        height:376
                        color:"#FFFFFF"
                    }
                }

                Rectangle{
                    width: parent.width
                    height:loader.height+66 // 66数字是一点一点调出来的
                    topLeftRadius: 8
                    topRightRadius: 8
                    color:"#178FCD"
                    // color:"red"
                    Rectangle{
                        x:50;y:18;width:16;height:31;
                        color:"#FFFFFF"
                    }
                    Label{
                        x:78;y:14;
                        color:"#FFFFFF"
                        text:"搅拌过程数据详情"
                        verticalAlignment: "AlignVCenter"
                        font.pixelSize: 30
                    }
                    Rectangle{
                        y:68;
                        width: parent.width
                        height:loader.height
                        color:"#FFFFFF"
                        Loader {
                            id: loader
                            anchors.top: parent.top
                            anchors.left: parent.left
                            anchors.right: parent.right
                            source: "qrc:/pages/BatchDataListPage.qml"
                            // visible: currentPage === "main"
                        }
                    }
                }
            }
        }
    }
}
